#ifndef __FORWARD_PAIR_H_INCLUDED__
#define __FORWARD_PAIR_H_INCLUDED__

#include "forward_util.h"
#include <netinet/in.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * 转发会话结构
 */
class forward_pair{

public:

	forward_pair(){
		reset();
	}

	forward_pair(sockaddr_in& in, sockaddr_in& out){
		reset();
		si_in = in;
		si_out = out;
	}

	~forward_pair(){
	}

	inline void reset(){
		si_in.sin_family = PF_INET;
		si_in.sin_port = htons(0);
		si_in.sin_addr.s_addr = 0;

		si_out.sin_family = PF_INET;
		si_out.sin_port = htons(0);
		si_out.sin_addr.s_addr = 0;
	}

	inline string get_src_addr(){
		return forward_util::get_addr_by_sockaddr_in(si_in);
	}

	inline string get_dst_addr(){
		return forward_util::get_addr_by_sockaddr_in(si_out);
	}

	inline unsigned short get_src_port(){
		return forward_util::get_port_by_sockaddr_in(si_in);
	}

	inline unsigned short get_dst_port(){
		return forward_util::get_port_by_sockaddr_in(si_out);
	}

	inline string to_string(){
		return forward_util::get_sockaddr_str(si_in) + " <=> " + forward_util::get_sockaddr_str(si_out);
	}

	inline bool is_valid(){
		return (!get_src_port() || !get_dst_port());
	}

	sockaddr_in si_in;
	sockaddr_in si_out;
};

#ifdef __cplusplus
}
#endif

#endif // __FORWARD_PAIR_H_INCLUDED__
